package com.jolink.omiis.wechat.outer.custom;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jolink.omiis.wechat.outer.AbstractWeChatController;

/**
 * 58-M站
 * @author WangYanqing
 *
 */
@Controller
@RequestMapping("/customer/register")
public class WeChat58View extends AbstractWeChatController {
	private static Logger logger = LoggerFactory.getLogger(WeChat58View.class);

	@RequestMapping(method = RequestMethod.GET)
	public void get(HttpServletRequest request, HttpServletResponse response) {
		long t1 = System.currentTimeMillis();
		logger.info("接收到腾讯重定向至58-M站点请求：{}，InstanceId：{}", request.getParameterMap(), this.hashCode());
		try {
			String code = request.getParameter("code");
			String state = request.getParameter("state");
			String appId = "11111";
			logger.info("调用全媒体客服接口查询微信客户信息。");
			logger.info("执行微信号与CRM-微信客户号绑定。");
			response.getWriter().flush();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			try {
				response.getWriter().write("ok");
			} catch (IOException e1) {
				logger.error(e.getMessage(), e);
			}
			return;
		}
		long t2 = System.currentTimeMillis();
		logger.info("处理腾讯重定向至58-M站点请求完成，结果：{}，耗时：{}毫秒。", "", (t2 - t1));
	}
}
